<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>Document</title>
  <!-- 导入页面的基本样式 -->
  <link rel="stylesheet" href="./css/search.css" />
  <link rel="stylesheet" href="./lodash/lodash.mini.js">
  <!-- 导入 jQuery -->
  <script src="./lib/jquery.js"></script>
</head>

<body>
  <div class="container">
    <!-- Logo -->
    <img src="./images/taobao_logo.png" alt="" class="logo" />

    <div class="box">
      <!-- tab 栏 -->
      <div class="tabs">
        <div class="tab-active">宝贝</div>
        <div>店铺</div>
      </div>
      <!-- 搜索区域（搜索框和搜索按钮） -->
      <div class="search-box">
        <input id="ipt" type="text" class="ipt" placeholder="请输入要搜索的内容" /><button class="btnSearch">
          搜索
        </button>
      </div>
      <!-- 搜索建议列表 -->
      <div id="suggest-list">
        <div class="suggest-item">哈哈</div>
      </div>
    </div>
  </div>

  <script>
    $(function () {
      // 接口地址：https://suggest.taobao.com/sug?q=搜索关键字
    $('#ipt').on('keyup',_.debounce(function () {
      
      const content = $(this).val().trim()

      $.ajax({
        url:`https://suggest.taobao.com/sug?q=${content}`,
        
        dataType:'JASONP',
        success({result}){
          const str = result.map(item=>`
          <div class="suggest-item">${item[0]}</div>
          `).join('')
          $('#suggest-list').html(str).show()
        }
      })

    }, 300))
    
    
    
    })
  </script>
</body>

</html>